package com.example.finance_manager.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.finance_manager.R;
import com.example.finance_manager.models.Payout;

import java.util.List;

public class ExpendAdapter extends BaseAdapter {
    private final List<Payout> mList;
    private final LayoutInflater mInflater;

    public ExpendAdapter(Context mContext, List<Payout> mList) {
        this.mList = mList;
        this.mInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList == null ? null : mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {
        View item;
        if (convertView == null) {
            item = mInflater.inflate(R.layout.item_my_expend, parent, false);
        } else {
            item = convertView;
        }
        TextView tvTime = item.findViewById(R.id.tv_item_expend_time);
        TextView tvType = item.findViewById(R.id.tv_item_expend_type);
        TextView tvAddress = item.findViewById(R.id.tv_item_expend_address);
        TextView tvOther = item.findViewById(R.id.tv_item_expend_other);
        TextView tvMoney = item.findViewById(R.id.tv_item_expend_money);
        Payout payout = mList.get(i);
        tvTime.setText(payout.getTime());
        tvMoney.setText(payout.getMoney().toString());
        tvType.setText(payout.getType());
        tvAddress.setText(payout.getAddress());
        tvOther.setText(payout.getOther());
        return item;
    }
}
